package com.museum.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.museum.entity.DO.Permission;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Ruiwen
 * @since 2020-12-19
 */
@Repository

public interface PermissionMapper extends BaseMapper<Permission> {
    @Select("select permission_id from permission")
    List<Integer> selectPermissionIds();

    @Select("select * from permission where permission_id = #{permissionId}")
    Permission selectOneByPermission(Integer permissionId);

    /**
     * 根据permissionID 获取parentID
     *
     * @param permissionID
     * @return
     */
    @Select("select permission_id FROM permission WHERE parent_id=#{permissionID}")
    List<Integer> getParentIdByPermissionIds(Integer permissionID);

    /**
     * 根据permissionID获取父节点
     *
     * @param permissionID
     * @return
     */
    @Select("select parent_id FROM permission WHERE permission_id=#{permissionID}")
    Integer getParentIdByPermissionId(Integer permissionID);

    @Update("update permission set `status` =1 where permission_id=#{permissionID}")
    Integer closePermission(Integer treeChild);


    @Select("SELECT permission_id FROM permission WHERE `status`=0 ")
    List<Integer> getCanUsePermissionIDs();

    @Update("update permission set `status` =0 where permission_id=#{permissionID} ")
    int openPermissionByPermissionID(Integer permissionID );
}
